package net.stsmedia.roo.addon.heroku;

import java.util.logging.Logger;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.springframework.roo.shell.CliAvailabilityIndicator;
import org.springframework.roo.shell.CliCommand;
import org.springframework.roo.shell.CommandMarker;

/**
 * 
 * @author Stefan Schmidt
 * @since 0.1
 */
@Component 
@Service
public class HerokuCommands implements CommandMarker { // All command types must implement the CommandMarker interface
	
	/**
	 * Get hold of a JDK Logger
	 */
	private Logger log = Logger.getLogger(getClass().getName());

	/**
	 * Get a reference to the HerokuOperations from the underlying OSGi container
	 */
	@Reference private HerokuOperations operations; 

	/**
	 * Define when "heroku setup" command should be visible in the Roo shell. 
	 * 
	 * @return true (default) if the command should be visible at this stage, false otherwise
	 */
	@CliAvailabilityIndicator("heroku setup") // Define the exact command name
	public boolean herokuSetup() {
		return operations.isHerokuSetupCommandAvailable();
	}

	@CliCommand(value = "heroku setup", help="Configure project for Heroku cloud deployment")
	public void setup() {
		operations.manageApplicationContext();
		operations.installMavenPlugin();
		operations.createProcfile();
		log.warning("Your project as been configured for Heroku deployment. " +
				"\nPlease also add the following environment variables to your system:\n" +
				"export DATABASE_URL=postgres://stewie:rupert@localhost/heroku\n\n");
		}
}